﻿namespace Toybox.CookieGetterSharp.Safari
{
  class SafariBrowserManager : IBrowserManager
  {
    const string COOKIEPATH = "%APPDATA%\\Apple Computer\\Safari\\Cookies\\Cookies.plist";
    const string BINARYCOOKIEPATH = "%APPDATA%\\Apple Computer\\Safari\\Cookies\\Cookies.binarycookies";

    #region IBrowserManager メンバ

    public BrowserType BrowserType
    {
      get { return BrowserType.Safari; }
    }

    public ICookieGetter CreateDefaultCookieGetter()
    {
      string path = null;
      string temp = null;
      
      temp = Utility.ReplacePathSymbols(COOKIEPATH);
      if (System.IO.File.Exists(temp))
        path = temp;

      temp = Utility.ReplacePathSymbols(BINARYCOOKIEPATH);
      if (System.IO.File.Exists(temp))
        path = temp;

      CookieStatus status = new CookieStatus(this.BrowserType.ToString(), path, this.BrowserType, PathType.File);
      return new SafariCookieGetter(status);
    }

    public ICookieGetter[] CreateCookieGetters()
    {
      return new ICookieGetter[] { CreateDefaultCookieGetter() };
    }

    #endregion
  }
}
